package com.jumpy.entities;

import org.andengine.entity.scene.IOnSceneTouchListener;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.input.touch.TouchEvent;

import com.jumpy.MovingRect;
import com.jumpy.managers.ResourceManager;

public class JumpyScene extends Scene implements IOnSceneTouchListener {

	private final Techo techo;
	private final Character character;

	public JumpyScene() {
		this.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));

		final float centerX = (MovingRect.CAMERA_WIDTH - ResourceManager.mFaceTextureRegion2
				.getWidth()) / 2;
		final float centerY = (MovingRect.CAMERA_HEIGHT - ResourceManager.mFaceTextureRegion2
				.getHeight()) * 0.75f;
		techo = new Techo(64, 0, ResourceManager.mFaceTextureRegion,
				ResourceManager.mActivity.getVertexBufferObjectManager());
		character = new Character(centerX, centerY,
				ResourceManager.mFaceTextureRegion2,
				ResourceManager.mActivity.getVertexBufferObjectManager());

		this.attachChild(techo);
		this.attachChild(character);

		this.setOnSceneTouchListener(this);
	}

	@Override
	public boolean onSceneTouchEvent(final Scene pScene,
			final TouchEvent pSceneTouchEvent) {
		// Debug.d("hola+ " + pSceneTouchEvent.getAction());
		switch (pSceneTouchEvent.getAction()) {
		case TouchEvent.ACTION_DOWN:
			this.character.moveUntil(pSceneTouchEvent.getX());
			break;
		case TouchEvent.ACTION_UP:
			this.character.stop();
			break;
		case TouchEvent.ACTION_MOVE:
			this.character.moveUntil(pSceneTouchEvent.getX());
			break;
		}
		return true;
	}

}
